package com.algorithm.排序;

import com.algorithm.排序.tools.Asserts;
import com.algorithm.排序.tools.Integers;
import com.algorithm.排序.基于比较的排序.*;
import com.algorithm.排序.基于计数的排序.基数排序;
import com.algorithm.排序.基于计数的排序.计数排序;
import com.algorithm.排序.基于计数的排序.计数排序_优化;
import org.junit.jupiter.api.Test;
import java.util.Arrays;

public class SortTest {
    @SafeVarargs
    static void testSorts(Integer[] array, Sort<Integer>... sorts) {
        for (Sort<Integer> sort : sorts) {
            Integer[] newArray = Integers.copy(array);
            sort.sort(newArray);
            Asserts.test(Integers.isAscOrder(newArray));
            Integers.println(newArray);
        }

        Arrays.sort(sorts);

        for (Sort<Integer> sort : sorts) {
            System.out.println(sort);
        }
    }


    @Test
    public void test (){
        //Integers.isAscOrder(array):能判断数组是否是升序的
        //System.out.println(Integers.isAscOrder(array));

        //断言
        //Asserts.test(Integers.isAscOrder(array));

        //生产随机数组
        //Integer[] array = Integers.random(1000, 1, 20000);

        //复制一个数据相同的数组
        //Integer[] array2 = Integers.copy(array);

        //升序产生一个数组 20,21,22,23,24....51,52
        //Integer[] array1 = Integers.ascOrder(20, 52);

        //产生一个尾部升序的数组,最后一个参数为期望是数字乱序的数量
        //Integers.tailAscOrder(1, 20, 10);

       /* Times.test("bubbleSort",()->{
            bubbleSort(array);
        });*/

        //打印此数组
        //Integers.println(array);
    }
    @Test
    public void test1(){
        冒泡排序<Integer> 冒泡排序 = new 冒泡排序<Integer>();
        Integer[] array = Integers.random(20, 1, 100);
        Integers.println(array);
        冒泡排序.sort(array);
        Integers.println(array);
    }

    /**
     * 
     */
    @Test
    public void  test2(){
        Integer[] array = Integers.random(1000, 1, 20000);

        new 堆排序<Integer>().sort(array);

        Integers.println(array);

        Asserts.test(Integers.isAscOrder(array));
    }

    @Test
    public void  test3(){
        Integer[] array = Integers.random(5000, 1, 10000);

      /*  Times.test("heapSort",()->{
            new 堆排序().sort(array);
        });
        Times.test("bubbleSort",()->{
            new 冒泡排序().sort(array2);
        });
        Times.test("selectionSort",()->{
            new 选择排序().sort(array3);
        });*/

        testSorts(array,new 堆排序<Integer>(),new 选择排序<Integer>(),new 冒泡排序<Integer>());
    }

    @Test
    public void test4(){
        //Integer[] array = Integers.random(5000, 1, 10000);
        Integer[] array = {8,5,63,1,5,6,8,9,1};


        testSorts(array,
                //new 堆排序<Integer>(),
                //new 选择排序<Integer>(),
                //new 冒泡排序<Integer>(),
                //new 插入排序1_交换<Integer>(),
                //new 插入排序3_二分搜索挪动<>(),
                //new 归并排序<>(),
                //new 快速排序<>(),
                //new 希尔排序<>(),
                //new 计数排序(),
                //new 计数排序_优化(),
                new 基数排序()
        );
    }

    @Test
    public void test5(){
        Integer[] array = Integers.random(5000, 1, 10000);

        testSorts(array,new 插入排序1_交换<Integer>());
    }

    @Test
    public void test6(){
      Integer[] integers = {0,1,2,3,4};
      Integer[] integers2 = {5,6,7,8,9};
      int i = 1;
      int j = 2;
        integers[++i] = integers2[++j];
        System.out.println(i + j);
    }
}
